package com.practice.system.controller;

import com.practice.system.dto.PlanningDetailDto;
import com.practice.system.mapper.LinkPlanningDetailchedulingMapper;
import com.practice.system.pojo.PlanningDetail;
import com.practice.system.service.PlanningDetailService;
import com.practice.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/planningDetail")
public class PlanningDetailController {
    @Autowired
    PlanningDetailService planningDetailService;

    @Autowired
    LinkPlanningDetailchedulingMapper linkPlanningDetailchedulingMapper;
    //来自计划表的id
    @GetMapping("/listbyschedulingid/{schedulingid}")
    public R listbyschedulingid(@PathVariable("schedulingid") String id){
        return planningDetailService.listbyschedulingid(id);
    }

    @PostMapping("/update")
    public R update(@RequestBody PlanningDetail planningDetail){
        return planningDetailService.update(planningDetail);
    }

    @PostMapping("/deleteByTwoId")
    public R deleteByTwoId(String planningShcedulingId,String planningDetailId){
        if(linkPlanningDetailchedulingMapper.deleteByTwoId(planningShcedulingId,planningDetailId))
            return R.ok();
        else
            return R.error();
    }

    @PostMapping("/add")
    public R add(PlanningDetailDto planningDetailDto){
        return planningDetailService.add(planningDetailDto);
    }
}
